def get_text_polynomial_as_binary_string(data):
    tokens = ("x","x**","x*","x^","x^^")
    currentToken = "+"
    currentNumber = ""
    inNumber = False
    polynom = 0
    def isValidToken(token):
        if len(token):
            if token[0]=='+':
                if token[1:] in tokens:
                    return True
        return False
    for i in ''.join(data.split()):
        if i.isdigit():
            inNumber = True
            currentNumber += i
        else:
            if inNumber:
                if isValidToken(currentToken):
                    polynom |= 1<<int(currentNumber)
                elif currentToken == "+" and currentNumber == "1":
                    polynom |= 1
                else:
                    return None
                inNumber = False
                currentNumber = ""
                currentToken = ""
            currentToken += i
    if inNumber:
        if isValidToken(currentToken):
            polynom |= 1<<int(currentNumber)
        elif currentToken == "+" and currentNumber == "1":
            polynom |= 1
        else:
            return None
        currentToken = ""
    if currentToken != "":
        return None
    return polynom


def get_text_polynomial_from_binary_string(data):
    token = 'x**'
    polynomial = ''
    data = list(data)
    for i in range(0,len(data)):
        data[i] = int(data[i])
        coef = len(data)-i-1
        if data[i]:
            if coef == 0:
                polynomial += '1'
            elif coef == 1:
                polynomial += 'x'
            else:
                polynomial += token+str(coef)
            polynomial += ' + '
    if polynomial == '':
        return 0;
    else:
        return polynomial[:-2]
